
$(function () {

    //初始化加载datagrid
    $('#dg1').datagrid({
        method: 'post',
        url: ROOT_PATH + '/workflow/workflowDef/findWorkflowDefList.shtml',
        /*queryParams: {
            sort: 'sort',
            order: 'desc',
            deptCode: deptCode
        },*/
        //idField: 'id',
        fitColumns: true,
        pagination: true,
        rownumbers: true,
        sortOrder: true,
        striped: true,
        fit: true,
        columns: [[
            {field: 'id', width: 80, checkbox: true},
            {field: 'processId', title: '业务流程标识', width: 100, sortable: true},
            {field: 'displayName', title: '业务流程名称', width: 80, sortable: true},
            {field: 'version',title: '流程版本'},
            {
                field: 'state',
                title: '流程状态',
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return '已发布';
                    } else {
                        return '未发布';
                    }
                }
            },
            {field: 'businessIdentity', title: '关联业务标识'},
            {field: 'businessName', title: '关联业务名称'},
            {field: 'publishUser', title: '发布人'},
            {field: 'publishTime', title: '发布时间',sortable:true,
                formatter:function(value,row,index){
                    if(value==null || isNaN(value)){
                        return '';
                    }else{
                        function add0(m){return m<10?'0'+m:m }
                        var date = new Date(parseInt(value));
                        var year = date.getFullYear();
                        var month = date.getMonth()+1;
                        var day = date.getDate();
                        var hour=date.getHours();
                        var minute=date.getMinutes();
                        var second=date.getSeconds();
                        return year+'-'+add0(month)+'-'+add0(day)+' '+add0(hour)+':'+add0(minute)+':'+add0(second);
                    }


                }
            },
            {field: 'description', title: '备注', width: 100}
        ]]
    });
    /***
     * 查询按钮事件
     */
    $('#btn_search').on("click", function () {
        $('#dg1').datagrid('load', $('#tb1').find(':input').serializeJson());
    });

    /**
     * 打开流程创建页面
     * @Author: wangqingguo
     * @Date: 2017/3/14
     */
    $('#btn_workflow_add').on('click',function(){
        var index = parent.layer.open({
            type: 2,
            title: '新建流程',
            area: ['1000px', '700px'],
            content: ROOT_PATH + '/workflow/workflowDef/add.shtml',
            end:function(){
                $('#dg1').datagrid('reload');
            }
        });
    });
    /***
     * 打开流程编辑页面
     * @returns {boolean}
     */
    $('#btn_workflow_edit').on('click',function(){
        var $selected = $('#dg1').datagrid('getSelections');
        if ($selected.length != 1) {
            layer.alert('请选择一个业务流程！');
            return false;
        }
        var index = parent.layer.open({
            type: 2,
            title: '编辑流程',
            area: ['1000px', '700px'],
            content: ROOT_PATH + '/workflow/workflowDef/add.shtml?processId=' + $selected[0].processId,
            end:function(){
                $('#dg1').datagrid('reload');
            }
        });
    });

});